package org.htmlparser.filters;

import java.util.Locale;
import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Text;

public class StringFilter
  implements NodeFilter
{
  protected boolean mCaseSensitive;
  protected Locale mLocale;
  protected String mPattern;
  protected String mUpperPattern;

  public StringFilter()
  {
    this("", false);
  }

  public StringFilter(String paramString)
  {
    this(paramString, false);
  }

  public StringFilter(String paramString, boolean paramBoolean)
  {
    this(paramString, paramBoolean, null);
  }

  public StringFilter(String paramString, boolean paramBoolean, Locale paramLocale)
  {
    this.mPattern = paramString;
    this.mCaseSensitive = paramBoolean;
    if (paramLocale == null)
      localLocale = Locale.getDefault();
    while (true)
    {
      this.mLocale = localLocale;
      setUpperPattern();
      return;
      localLocale = paramLocale;
    }
  }

  public boolean accept(Node paramNode)
  {
    int i = 0;
    if (paramNode instanceof Text)
    {
      String str = ((Text)paramNode).getText();
      if (!(getCaseSensitive()))
        str = str.toUpperCase(getLocale());
      if (-1 == str.indexOf(this.mUpperPattern))
        break label52;
      i = 1;
    }
    while (true)
    {
      return i;
      label52: i = 0;
    }
  }

  public boolean getCaseSensitive()
  {
    return this.mCaseSensitive;
  }

  public Locale getLocale()
  {
    return this.mLocale;
  }

  public String getPattern()
  {
    return this.mPattern;
  }

  public void setCaseSensitive(boolean paramBoolean)
  {
    this.mCaseSensitive = paramBoolean;
    setUpperPattern();
  }

  public void setLocale(Locale paramLocale)
  {
    this.mLocale = paramLocale;
    setUpperPattern();
  }

  public void setPattern(String paramString)
  {
    this.mPattern = paramString;
    setUpperPattern();
  }

  protected void setUpperPattern()
  {
    if (getCaseSensitive())
      this.mUpperPattern = getPattern();
    while (true)
    {
      return;
      this.mUpperPattern = getPattern().toUpperCase(getLocale());
    }
  }
}